﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace aDream
{
    public class RealEstateAgency
    {
        private Propertys propertys;
        private DataConnection connection;

        
        public RealEstateAgency()
        {
            connection = new DataConnection();
            propertys = new Propertys(connection);
            setup();
        }

        public Propertys getPropertys()
        {
            return propertys;
        }


        private void setup()
        {
            setupPropertys(connection);

        }

        private void setupPropertys(DataConnection connection)
         {
            DataTable dt;
            dt = connection.ExecuteReturningQuery("select idProperty, type, description, details, streetNo, streetName, suburb, postCode, state from Property natural join Address;");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                propertys.add(Convert.ToInt32(dt.Rows[i].ItemArray[0].ToString()),
                dt.Rows[i].ItemArray[1].ToString(),
                dt.Rows[i].ItemArray[2].ToString(),
                dt.Rows[i].ItemArray[3].ToString(),
                dt.Rows[i].ItemArray[4].ToString(),
                dt.Rows[i].ItemArray[5].ToString(),
                dt.Rows[i].ItemArray[6].ToString(),
                dt.Rows[i].ItemArray[7].ToString(),
                dt.Rows[i].ItemArray[8].ToString());                   
            }

        }

    }
}
